package com.pig4cloud.pigx.contract.api.v1.controller;

import com.alibaba.fastjson.JSONObject;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.customize.api.annotation.OpenApi;
import com.pig4cloud.pigx.common.log.annotation.SysLog;
import com.pig4cloud.pigx.common.sentinel.handle.PigxUrlBlockHandler;
import com.pig4cloud.pigx.contract.api.v1.service.SymbolServiceV1;
import com.pig4cloud.pigx.contract.open.api.vo.OpenApiSymbol24hTickerVOV1;
import com.pig4cloud.pigx.contract.open.api.vo.OpenApiSymbolDetailsVOV1;
import com.pig4cloud.pigx.contract.open.api.vo.OpenApiSymbolHandlingRateVOV1;
import com.pig4cloud.pigx.user.enums.UserApiKeyEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * 开放API - 币对 - v1版本
 *
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/contract/symbol" )
@Api(value = "api_symbol_v1", tags = "开放api-币对")
public class SymbolControllerV1 {

	private final SymbolServiceV1 service;

	/**
	 * 获取币对详情
	 * @return R
	 */
	@ApiOperation(value = "获取币对详情", notes = "获取币对详情")
	@SysLog("获取币对详情" )
	@OpenApi(version = "1",permission = UserApiKeyEnum.Permission.READ,needSignature = true)
	@GetMapping("/detail")
	public R<OpenApiSymbolDetailsVOV1> getSymbol(@RequestParam("symbolName") String symbolName) {
		return service.getSymbol(symbolName);
	}

	/**
	 * 获取币对最新价格
	 * @return R
	 */
	@ApiOperation(value = "获取币对最新价格", notes = "获取币对最新价格")
	@SysLog("获取币对最新价格" )
	@OpenApi(version = "1",permission = UserApiKeyEnum.Permission.READ,needSignature = true)
	@GetMapping("/last_price")
	public R<BigDecimal> getSymbolLastPrice(@RequestParam("symbolName") String symbolName) {
		return service.getSymbolLastPrice(symbolName);
	}

	/**
	 * 获取币对标记价格
	 * @return R
	 */
	@ApiOperation(value = "获取币对标记价格", notes = "获取币对标记价格")
	@SysLog("获取币对标记价格" )
	@OpenApi(version = "1",permission = UserApiKeyEnum.Permission.READ,needSignature = true)
	@GetMapping("/index_price")
	public R<BigDecimal> getSymbolIndexPrice(@RequestParam("symbolName") String symbolName) {
		return service.getSymbolIndexPrice(symbolName);
	}

	/**
	 * 获取币对指数价格
	 * @return R
	 */
	@ApiOperation(value = "获取币对指数价格", notes = "获取币对指数价格")
	@SysLog("获取币对指数价格" )
	@OpenApi(version = "1",permission = UserApiKeyEnum.Permission.READ,needSignature = true)
	@GetMapping("/mark_price")
	public R<BigDecimal> getSymbolMarkPrice(@RequestParam("symbolName") String symbolName) {
		return service.getSymbolMarkPrice(symbolName);
	}

	/**
	 * 获取币对24行情
	 * @param symbolName 币对名称
	 * @return 币对24行情
	 */
	@ApiOperation(value = "获取币对24行情", notes = "获取币对24行情")
	@SysLog("获取币对24行情" )
	@OpenApi(version = "1",permission = UserApiKeyEnum.Permission.READ,needSignature = true)
	@GetMapping("/24h_ticker")
	public R<OpenApiSymbol24hTickerVOV1> getSymbol24hTicker(@RequestParam("symbolName") String symbolName){
		return service.getSymbol24hTicker(symbolName);
	}

	/**
	 * 获取币对手续费率
	 * @param symbolName 币对名称
	 * @return 手续费
	 */
	@ApiOperation(value = "获取币对手续费率", notes = "获取币对手续费率")
	@SysLog("获取币对手续费率" )
	@OpenApi(version = "1",permission = UserApiKeyEnum.Permission.READ,needSignature = true)
	@GetMapping("/handling_rate")
	public R<OpenApiSymbolHandlingRateVOV1> getSymbolHandlingRate(@RequestParam("symbolName") String symbolName) {
		return service.getSymbolHandlingRate(symbolName);
	}

	/**
	 * 获取币对深度图
	 * @param symbolName 币对名称
	 * @param level 深度等级
	 * @return r
	 */
	@ApiOperation(value = "获取币对深度图", notes = "获取币对深度图")
	@SysLog("获取币对深度图" )
	@OpenApi(version = "1",permission = UserApiKeyEnum.Permission.READ,needSignature = true)
	@GetMapping("/depth")
	public R<JSONObject> getSymbolDepth(@RequestParam("symbolName") String symbolName,@RequestParam("level")  String level) {
		return service.getSymbolDepth(symbolName,level);
	}

	/**
	 * 获取币对深度等级选项
	 * @param symbolName 币对名称
	 * @return r
	 */
	@ApiOperation(value = "获取币对深度等级", notes = "获取币对深度等级选项")
	@SysLog("获取币对深度等级选项" )
	@OpenApi(version = "1",permission = UserApiKeyEnum.Permission.READ,needSignature = true)
	@GetMapping("/depth/level")
	public R<List<String>> getLevelFromRedis(@RequestParam("symbolName") String symbolName) {
		return service.getLevelFromRedis(symbolName);
	}

}
